package com.burstly.lib.component.networkcomponent;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Handler;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import com.burstly.lib.util.LoggerExt;

class DebugGestureListener extends GestureDetector.SimpleOnGestureListener
  implements Runnable
{
  private static final int GESTURE_INPUT_TIMEOUT = 2000;
  private static final int INTERCEPT_INPUT_MASK = 2;
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final int LONG_PRESSED_MASK = 1;
  private static final int SHOWING_DEBUG_INFO = 4;
  private static final String TAG = DebugGestureListener.class.getSimpleName();
  private volatile int mDebugState;
  private final HierarchyAwareLayout mDebuggableView;
  private GestureDetector mGestureDetector;
  private final Handler mUiHandler = new Handler();

  DebugGestureListener(HierarchyAwareLayout paramHierarchyAwareLayout)
  {
    this.mDebuggableView = paramHierarchyAwareLayout;
  }

  private boolean checkFlag(int paramInt)
  {
    return (paramInt & this.mDebugState) == paramInt;
  }

  private void clearDebugState()
  {
    this.mDebugState = 0;
  }

  private void clearFlag(int paramInt)
  {
    this.mDebugState &= (paramInt ^ 0xFFFFFFFF);
  }

  private void setFlag(int paramInt)
  {
    this.mDebugState = (paramInt | this.mDebugState);
  }

  boolean isDebugModeEnabled()
  {
    return checkFlag(2);
  }

  public boolean onDown(MotionEvent paramMotionEvent)
  {
    if (checkFlag(1))
    {
      clearFlag(1);
      this.mUiHandler.removeCallbacks(this);
      this.mGestureDetector.setIsLongpressEnabled(true);
      LOG.logDebug(TAG, "Debug session interrupted", new Object[0]);
    }
    boolean bool1;
    if (!checkFlag(4))
    {
      boolean bool2 = checkFlag(2);
      bool1 = false;
      if (!bool2);
    }
    else
    {
      bool1 = true;
    }
    return bool1;
  }

  public boolean onFling(MotionEvent paramMotionEvent1, MotionEvent paramMotionEvent2, float paramFloat1, float paramFloat2)
  {
    if (isDebugModeEnabled())
    {
      this.mUiHandler.removeCallbacks(this);
      clearDebugState();
      setFlag(4);
      this.mDebuggableView.showDebugView();
    }
    while (true)
    {
      return super.onFling(paramMotionEvent1, paramMotionEvent2, paramFloat1, paramFloat2);
      if (checkFlag(4))
      {
        this.mDebuggableView.showAdView();
        clearDebugState();
        this.mGestureDetector.setIsLongpressEnabled(true);
      }
    }
  }

  public void onLongPress(MotionEvent paramMotionEvent)
  {
    LOG.logDebug(TAG, "Long press captured", new Object[0]);
    setFlag(1);
    this.mGestureDetector.setIsLongpressEnabled(false);
    this.mUiHandler.post(this);
  }

  public boolean onSingleTapConfirmed(MotionEvent paramMotionEvent)
  {
    if (checkFlag(4))
    {
      new AlertDialog.Builder(this.mDebuggableView.getContext()).setTitle("Info").setCancelable(true).setMessage(this.mDebuggableView.toString()).create().show();
      return true;
    }
    return super.onSingleTapConfirmed(paramMotionEvent);
  }

  public void run()
  {
    if (checkFlag(1))
    {
      LOG.logDebug(TAG, "Debug mode enabled, waiting for gesture.", new Object[0]);
      setFlag(2);
      clearFlag(1);
      this.mUiHandler.postDelayed(this, 2000L);
      return;
    }
    LOG.logDebug(TAG, "Debug mode disabled. Time is up.", new Object[0]);
    clearDebugState();
    this.mGestureDetector.setIsLongpressEnabled(true);
  }

  void setGestureDetector(GestureDetector paramGestureDetector)
  {
    this.mGestureDetector = paramGestureDetector;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.DebugGestureListener
 * JD-Core Version:    0.6.2
 */